FROM registry.cn-hangzhou.aliyuncs.com/hongxuan/golang-alpine:latest AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0

RUN yum update  -y && yum install  epel-release git  protobuf-compiler -y
# 设置Go模块代理
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
# 安装goctl
#RUN go install github.com/zeromicro/go-zero/tools/goctl@latest
WORKDIR /goctl
RUN git --version
RUN git clone https://gitee.com/HongXuandaozun/go-zero.git
RUN cd /goctl/go-zero && pwd
WORKDIR /goctl/go-zero
RUN git branch &&  git tag && git fetch --tags && git  checkout v1.8.1
WORKDIR /goctl/go-zero/tools/goctl
RUN  go build -o goctl \
    && ./goctl --version \
    && sudo mv goctl /usr/local/bin/ \
    && goctl --version
# 安装 protoc-gen-go 和 protoc-gen-go-grpc
#RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
#RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
RUN goctl env check -i -f --verbose
WORKDIR /build

RUN git clone https://gitee.com/HongXuandaozun/ptwo.git
# 切换目录到项目里面
WORKDIR /build/ptwo

RUN mv  go.mod go.mod.bak &&  go mod init gitee.com/HongXuandaozun/ptwo && goctl rpc protoc pone.proto --go_out=. --go-grpc_out=. --zrpc_out=.
RUN go mod tidy && rm pone.go
#RUN rm go.mod go.sum && mv go.mod.bak go.mod && go mod edit -go=1.22.9 && go mod tidy
# RUN rm go.mod  && go mod init gitee.com/HongXuandaozun/ptwo && go mod tidy

RUN go build -ldflags="-s -w" -o /app/ptwo .


FROM scratch

ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /app/ptwo /app/ptwo
COPY --from=builder /build/ptwo/etc/ptwo-api.yaml /app/etc/ptwo-api.yaml
EXPOSE 8888
CMD ["./ptwo", "-f", "etc/ptwo-api.yaml"]
